package com.HomeWorkhsp.chapter14.homework;

import java.util.ArrayList;

public class Homework01 {
    public static void main(String[] args) {
        News news1 = new News("新冠确诊病例超千万，数百万印度信徒赴恒河“圣浴”引民众担忧");
        News news2 = new News("男子突然想起两个月前钓的鱼还在网兜里，捞起一看赶紧放生");
        ArrayList<News> news = new ArrayList<>();
        news.add(news1);
        news.add(news2);
        for (int i = news.size() - 1; i >= 0; i--) {
            System.out.println(processTitle(news.get(i).getTitle()));
        }
    }
    public static String processTitle(String title){
        if (title == null) {
            return "";
        }
        if (title.length() > 15) {
            return title.substring(0,15) + "...";
        }else{
            return title;
        }


    }
}
class News{
    private String title;
    private String body;

    public News(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return "title='" + title + '\'' ;
    }
}
